<?php
/**
 * 地区管理
 * @author hanxiaojun
 *
 */
class AreaControl extends CommonControl{
	function listAction(){
		$this->page_size = 20;
		$page = isset($_GET['page']) ? $_GET['page'] : 1;
		$page = is_numeric($page) ? ($page > 0 ? $page : 1) : 1;
		
		$sql = "select id,code,code_num,country_en,country_cn from area";
		
		$array = M()->db->getRecordsByPage($page, $this->page_size, $sql);
		
		$this->out['pageCount'] = $array['pageCount'];
		$this->out['page'] = $array['page'];
		$this->out['pageDisplay'] = $this->pageDisplay;
		$this->out['data'] = $array['data'];
		$this->out['href'] = DOMAIN . '?act=area.list';
		$this->out['pagestring'] = $this->fetch("all.pages.html");
		$this->display('area.list.html');
	}
	
	
	function updateAction(){
		$name = $_GET['name'];
		$value = $_GET['value'];
		if(empty($name) || empty($value)){
			echo '0';
			return;
		}
		
		if(strlen($value) != 3){
			echo '2';
			return false;
		}
		$area_id = substr($name,strpos($name,'_')+1);
		$arr = array();
		//查看是否存在
		$check_sql = "select id from area where code_num='{$value}'";
		$check_id = M()->db->getString($check_sql);
		if(empty($check_id)){
			$arr['code_num'] = $value;
			M()->db->updateRecord("area", "id=$area_id", $arr);
			echo '1';
			return false;
		}else{
			echo '3';
			return false;
		}
	}
}